<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">


        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
                <!--<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>-->
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script src="../js/lay-module/http/http.js"></script>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;


        table.render({
            elem: '#currentTableId',
            url: $api + 'assit/expert/list/page?status=1',
            toolbar: '#toolbarDemo',
            headers: {
                Authorization: layui.data('table')['Authorization']
            },
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                // {type: "checkbox", width: 50},
                {type: "checkbox", width: 50},
                {field: 'expertId', title: 'ID', hide: true},
                {field: 'expertname', width: 100, title: '姓名'},
                {field: 'tchArea', width: 100, title: '技术领域'},
                {field: 'phone', width: 150, title: '联系方式'},
                {field: 'email', width: 200, title: '邮箱'},
                {
                    field: 'type', title: '专家类别', minWidth: 100, templet: function (res) {
                        // console.log(JSON.stringify(res).toString())
                        return getExpertType(res.type)
                    }
                }
            ]],
            limits: [1, 10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                console.log("我进来了")
                var data = table.checkStatus('currentTableId').data;

                var authIdList = []
                for (var i = 0; i < data.length; i++) {
                    authIdList.push(data[i].expertId)
                }

                $.ajax({
                    type: 'POST',
                    url: $api + "assit/expert/post",
                    dataType: 'json',
                    headers: {
                        'Authorization': layui.data('table')['Authorization']
                    },
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify({
                        'menusId': authIdList,
                        'roleId': unescape(getQueryString("id"))
                    }),
                    success: function (res) {
                        identifyCode(res)
                        if (res.code == 0) {
                            alert(res.message)
// 处理成功，返回到上层页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();
                            parent.layer.close(iframeIndex);
                        }

                    }
                });
            }
        });


    });
</script>

</body>
</html>